import { award, winningAmount, redemptioncode } from "@/api/goods";

export default {
  goRecord(){
    if (this.$router.currentRoute.path == "/detailRed") {
      setTimeout(() => {
        this.$router.replace({
          path: "/record",
        });
      }, 2000);
    }
    if (this.$router.currentRoute.path == "/record") {
      this.goDetail()
    }
  },
  //领取奖品按钮
  getPrice() {
    let { good_type } = this.goodsInfo;
   
    if (good_type > 2) {
      this.popupType = good_type == 3 ? 9 : 8;
    } else {
      if(good_type == 1){
        this.getMoney()
        return
      }else{
        this.popupType = 10;
      }
      
    }
    this.popupShow = true;
  },
  getCode() {
    let item = {
      g_o_id: this.goodsInfo.g_o_id,
      code: this.code,
    };
    redemptioncode(item).then((res) => {
      this.$copyText(res.data.str).then(
        () => {
          this.$toast("复制成功");
         
          this.goRecord()
          // 复制成功的操作
        },
        () => {
          this.$toast("复制失败");
          // 复制失败的操作
        }
      );
    });
  },
  getMoney() {
    let item = {
      g_o_id: this.goodsInfo.g_o_id,
      code: this.code,
    };
    winningAmount(item).then((res) => {
      this.$toast("提交成功");
      this.popupShow = false;
      this.goRecord()
    });
  },
  popupSub(e) {
    let item = {
      g_o_id: this.goodsInfo.g_o_id,
      type: this.goodsInfo.good_type,
      ...e,
    };
    let { good_type } = this.goodsInfo;
    award(item).then((res) => {
      this.$toast("提交成功");
      this.popupShow = false;

      if (good_type == 1) {
        this.getMoney();
        return;
      }
      if (good_type == 2 && this.$router.currentRoute.path == "/detailRed") {
        this.getCode();
        return;
      }
      this.goRecord()
    });
  },
};
